package com.huike.web.controller.report;

import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.report.domain.dto.PageParamsDTO;
import com.huike.report.domain.vo.ClueStatisticsListVO;
import com.huike.report.domain.vo.LineChartVo;
import com.huike.report.service.CluesStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @Description ClueStatisticsController
 * @Author moweihua
 * @Date 2023-10-2023/10/17
 */

@Slf4j
@RestController
@Api(tags = "线索统计相关接口")
@RequestMapping("/report")
@RequiredArgsConstructor
public class ClueStatisticsController {
    private final CluesStatisticsService cluesStatisticsService;

    /**
     * 线索统计新增线索数量报表接口
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @ApiOperation("线索统计新增线索数量报表接口")
    @GetMapping("/cluesStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVo cluesStatistics(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime, @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        log.info("线索统计新增线索数量报表接口:{},{}", beginCreateTime, endCreateTime);
        LineChartVo lineChartVo = cluesStatisticsService.cluesStatistics(beginCreateTime, endCreateTime);
        return lineChartVo;
    }

    /**
     * 线索统计明细列表接口
     * @param pageParamsDTO
     * @return
     */
    @ApiOperation("线索统计明细列表接口")
    @GetMapping("/cluesStatisticsList")
    public TableDataInfo<List<ClueStatisticsListVO>> cluesStatisticsList(PageParamsDTO pageParamsDTO) {
        log.info("线索统计明细列表接口:{}", pageParamsDTO);
        TableDataInfo<List<ClueStatisticsListVO>> tableDataInfo = cluesStatisticsService.pageList(pageParamsDTO);
        return tableDataInfo;
    }

    /**
     * 线索统计线索转换率报表接口
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @ApiOperation("线索统计线索转换率报表接口")
    @GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
    public AjaxResult<Map<String,Integer>> getVulnerabilityMap(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime, @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime){
        log.info("线索统计线索转换率报表接口：{},{}", beginCreateTime, endCreateTime);
        Map<String,Integer> map = cluesStatisticsService.getVulnerabilityMap(beginCreateTime, endCreateTime);
        return AjaxResult.success(map);
    }

}
